<template>
  <div>
    <!-- 瀑布布局 -->
    <!-- 中心部分 -->
    <div class="content">
      <div class="box">
        <div class="card" v-for="item in foods" :key="item.id">
          <router-link :to="`/detail/${item.id}`">
            <img :src="`/other/pic/${item.imga.split(',')[0]}`" alt="" />
            <div class="pdown">
              <div class="title">{{ item.title }}</div>
              <div class="rate">
                <p>{{ item.rate }}<van-icon name="star-o" color="#f5b400" /></p>
              </div>
            </div>
            <div class="time" v-if="item.updatetime">
              {{
                item.updatetime.slice(0, 10) +
                " " +
                item.updatetime.slice(12, 19)
              }}
            </div>
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
export default {
  data() {
    return {
      foods: [],
    };
  },
  mounted() {
    this.getData();
  },
  activated() {
    this.getData();
  },
  methods: {
    getData() {
      let city = sessionStorage.getItem("city");
      let url = `/recommend/around_city?type_id=2&city=${city}`;
      this.axios.get(url).then((res) => {
        this.foods = res.data.results;
      });
    },
    //顶部导航栏返回
    onClickLeft() {
      console.log("返回");
    },
    //搜索栏
    onSearch(val) {
      Toast(val);
    },
    onCancel() {
      Toast("取消");
    },
  },
};
</script>

<style lang='scss' scoped>
.pdown {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0px 4px;

  .rate {
    text-align: right;
    font-size: 18px;
    p {
      text-align: right;
      font-size: 14px;
      margin: 4px 0;
    }
  }
}
.time {
  color: #bbb;
  font-size: 12px;
  padding: 0px 8px 8px;
}
/*顶部导航栏 */
::v-deep .van-nav-bar__text {
  color: white;
}
::v-deep .van-icon {
  color: white;
}

.van-nav-bar__left span {
  color: white;
}
.van-nav-bar {
  background-color: #f5b400;
}
.van-nav-bar .van-icon {
  color: white;
}
::v-deep .van-nav-bar__title {
  color: white;
}
.van-nav-bar__text {
  color: white;
}

/* 搜索框*/
.van-search--show-action {
  margin: 0 auto;
  width: 100vw;
  padding: 2vw;
}

/*5个图标 */
.van-grid {
  width: 96vw;
  height: 25vw;
  margin: 5px auto;
  border: 1px solid #f5b400;
  border-radius: 30px;
  .van-grid-item--square {
    width: 25vw;
    height: 25vw;
    img {
      width: 50%;
      margin-top: 2vw;
    }
    p {
      color: black;
      font-size: 3vw;
    }
  }
}
::v-deep .van-grid-item__content {
  background-color: transparent;
}
</style>
<style lang='scss' src='./waterfall.scss' scoped></style>
